﻿<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:ViewModels="clr-namespace:ScrumSprintMonitor.Modules.WorkItemMonitor.ViewModels"
    xmlns:MonitorWindow="clr-namespace:ScrumSprintMonitor.UI.Wpf.Views.MonitorWindow;assembly=ScrumSprintMonitor.UI.Wpf">
    
    <DataTemplate x:Key="VerticalSprintTitleViewModel">
        <Grid Margin="0,0,20,0" VerticalAlignment="Stretch">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="90*" />
                <ColumnDefinition Width="20" />
            </Grid.ColumnDefinitions>
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto" />
                <RowDefinition Height="*" />
            </Grid.RowDefinitions>

            <Grid.Triggers>
                <EventTrigger RoutedEvent="Grid.MouseEnter">
                    <BeginStoryboard>
                        <Storyboard>
                            <DoubleAnimation Storyboard.TargetName="SprintConfigurationButton" Storyboard.TargetProperty="Opacity" To="1" Duration="0:0:0.2" />
                        </Storyboard>
                    </BeginStoryboard>
                </EventTrigger>
                <EventTrigger RoutedEvent="Grid.MouseLeave">
                    <BeginStoryboard>
                        <Storyboard>
                            <DoubleAnimation Storyboard.TargetName="SprintConfigurationButton" Storyboard.TargetProperty="Opacity" To="0.001" Duration="0:0:1" />
                        </Storyboard>
                    </BeginStoryboard>
                </EventTrigger>
            </Grid.Triggers>

            <Viewbox Grid.Row="1" x:Name="CurrentSprintName" RenderTransformOrigin="0.5,0.5">
                <Viewbox.LayoutTransform>
                    <RotateTransform Angle="-90"/>
                </Viewbox.LayoutTransform>

                <TextBlock Text="{Binding Path=CurrentSprintName}" TextAlignment="Center">
                    <TextBlock.Foreground>
                        <LinearGradientBrush>
                            <GradientBrush.GradientStops>
                                <GradientStop Color="LightGray"/>
                                <GradientStop Color="White" Offset="1"/>
                            </GradientBrush.GradientStops>
                        </LinearGradientBrush>
                    </TextBlock.Foreground>
                    <TextBlock.Effect>
                        <DropShadowEffect Direction="225"/>
                    </TextBlock.Effect>
                </TextBlock>
            </Viewbox>

            <Button Grid.Row="0" x:Name="SprintConfigurationButton" Opacity="0" Margin="0,0,0,10" Padding="5" Height="{Binding ElementName=CurrentSprintName, Path=ActualHeight}" Command="{Binding InvokeConfigurationCommand}">
                <Image Source="..\Resources\VistaICO\Config-Tools.png" Stretch="Uniform" />
            </Button>

            <MonitorWindow:SprintProgress Grid.Column="1" Grid.Row="1" Position="{Binding SprintPercentageCovered}" Orientation="Vertical" />
        </Grid>
    </DataTemplate>
    
    <DataTemplate x:Key="HorizontalSprintTitleViewModel">
        <Grid Margin="0,0,0,5" HorizontalAlignment="Center">
            <Grid.RowDefinitions>
                <RowDefinition Height="90*" />
                <RowDefinition Height="20" />
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition />
                <ColumnDefinition />
            </Grid.ColumnDefinitions>

            <Grid.Triggers>
                <EventTrigger RoutedEvent="Grid.MouseEnter">
                    <BeginStoryboard>
                        <Storyboard>
                            <DoubleAnimation Storyboard.TargetName="SprintConfigurationButton" Storyboard.TargetProperty="Opacity" To="1" Duration="0:0:0.2" />
                        </Storyboard>
                    </BeginStoryboard>
                </EventTrigger>
                <EventTrigger RoutedEvent="Grid.MouseLeave">
                    <BeginStoryboard>
                        <Storyboard>
                            <DoubleAnimation Storyboard.TargetName="SprintConfigurationButton" Storyboard.TargetProperty="Opacity" To="0.001" Duration="0:0:1" />
                        </Storyboard>
                    </BeginStoryboard>
                </EventTrigger>
            </Grid.Triggers>

            <Viewbox Grid.Column="0" x:Name="CurrentSprintName">
                <TextBlock Text="{Binding Path=CurrentSprintName}">
                        <TextBlock.Foreground>
                            <LinearGradientBrush>
                                <GradientBrush.GradientStops>
                                    <GradientStop Color="LightGray"/>
                                    <GradientStop Color="White" Offset="1"/>
                                </GradientBrush.GradientStops>
                            </LinearGradientBrush>
                        </TextBlock.Foreground>
                        <TextBlock.Effect>
                            <DropShadowEffect/>
                        </TextBlock.Effect>
                </TextBlock>
            </Viewbox>

            <MonitorWindow:SprintProgress Grid.Row="1" Position="{Binding SprintPercentageCovered}" />

            <Button Grid.Column="1" x:Name="SprintConfigurationButton" Opacity="0" Margin="10,0,0,0" Padding="5" Height="{Binding ElementName=CurrentSprintName, Path=ActualHeight}" Command="{Binding InvokeConfigurationCommand}">
                <Image Source="..\Resources\VistaICO\Config-Tools.png" Stretch="Uniform" />
            </Button>
        </Grid>
    </DataTemplate>

    <DataTemplate DataType="{x:Type ViewModels:SprintTitleViewModel}">
        <ContentPresenter Content="{Binding}" Focusable="False" Visibility="{Binding Visibility}">
            <ContentPresenter.Style>
                <Style TargetType="{x:Type ContentPresenter}">
                    <Setter Property="ContentTemplate">
                        <Setter.Value>
                            <DataTemplate />
                        </Setter.Value>
                    </Setter>

                    <Style.Triggers>
                        <MultiDataTrigger>
                            <MultiDataTrigger.Conditions>
                                <Condition Binding="{Binding Path=Visibility}" Value="Visible"/>
                                <Condition Binding="{Binding Path=PlaceholderOrientation}" Value="Horizontal"/>
                            </MultiDataTrigger.Conditions>
                            
                            <Setter Property="ContentTemplate" Value="{StaticResource HorizontalSprintTitleViewModel}" />
                        </MultiDataTrigger>

                        <MultiDataTrigger>
                            <MultiDataTrigger.Conditions>
                                <Condition Binding="{Binding Path=Visibility}" Value="Visible"/>
                                <Condition Binding="{Binding Path=PlaceholderOrientation}" Value="Vertical"/>
                            </MultiDataTrigger.Conditions>

                            <Setter Property="ContentTemplate" Value="{StaticResource VerticalSprintTitleViewModel}" />
                        </MultiDataTrigger>
                    </Style.Triggers>
                </Style>
            </ContentPresenter.Style>
        </ContentPresenter>
    </DataTemplate>
</ResourceDictionary>